package com.markhsiu.mysql.packet.client;

import java.nio.ByteBuffer;

import com.markhsiu.mysql.packet.BufferUtil;
import com.markhsiu.mysql.packet.MysqlPacket;
import com.markhsiu.mysql.packet.PacketWritable;
import com.markhsiu.mysql.session.Session;

/**
 * 查询请求报文
 * @author Mark Hsiu
 *
 */
public class QueryPacket extends MysqlPacket  implements PacketWritable{

	/**
	 * 查询标识符
	 */
	public byte flag;

	/**
	 * 查询的字符信息
	 */
	public byte[] queryStr;
	
	public QueryPacket(byte flag, byte[] queryStr) {
		this.flag = flag;
		this.queryStr = queryStr;
	}
	
	@Override
	public void write(Session session) {

		length = 1+ queryStr.length;
		
		ByteBuffer writeBuffer = session.writeBuffer;
		// 进行包大小的数据写入
		BufferUtil.writeUB3(writeBuffer, length);
		// 写入包在id
		writeBuffer.put(number);
		
		
		writeBuffer.put(flag);
		writeBuffer.put(queryStr);
		writeBuffer.flip();
	}


	@Override
	public String descrption() {
		return "查询请求报文";
	}

	
}
